(function() {
  app.controller('home_moreCtrl', function($scope, $rootScope, tradeApi, local_m, $filter, $interval, header_m, alertTip, $stateParams,$state) {
    $stateParams.type ? local_m.set('home_more_type', $stateParams.type) : $stateParams.type = local_m.get('home_more_type');
    $scope.home_list_actived = $stateParams.type;

    header_m.set({ title_c: $stateParams.type === 'report' ? '更多回报' : '更多动态' });
    $scope.init = function() {
      tradeApi.query({
        funcId: '000004',
        data: {
          oper_type: '1'
        }
      }).then(function(res) {
        angular.forEach(res, function(item) {
          item.sort_person_rate = parseFloat(item.person_rate);
        });
        $scope.home_list_report = res;
      });
      $scope.reload();
    };

    $scope.reload = function() {
      tradeApi.query({
        funcId: '000004',
        data: {
          oper_type: '0'
        }
      }).then(function(res) {
        $scope.home_list_create = res;
      });
    };

    $scope.go_strategy = function(item) {
      item.stkinfo = {
        code: item.product_code,
        name: item.product_name,
        market: item.market
      };
      $scope.storage.local('detail_codeinfo', item.stkinfo);
      local_m.set('selected_strategy_options',item);
      $state.go('strategy');
    };

    $scope.go_detail = function(item){
      item.income_balance = item.allot_balance;

      item.close_status = '2';
      $scope.storage.local('report_dl', item);
      $state.go('details-report', { source: true });
    };

    if ($stateParams.type !== 'report') {
      var timer = $interval(function() {
        $scope.reload();
      }, 5000);

      $scope.$on('$destroy', function() {
        $interval.cancel(timer);
        timer = null;
      });
    }
  });

})();
